import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Layout2 from "@/layout2";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/maintenanceControl',
    component: () => import('@/views/burnConfig/maintenanceControl'),
    hidden: true
  },
  {
    path: '/largeScreenDisplay',
    component: () => import('@/views/show/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/changePassword',
    component: () => import('@/views/passwordManage/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '庭审运维管控平台',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '庭审运维管控平台', icon: 'el-icon-s-help' }
    }]
  },
  {
    path: '/assemblyConfig',
    component: Layout,
    redirect: '/assemblyConfig',
    name: 'AssemblyConfig',
    children: [
      {
        path: 'assemblyConfig',
        name: '设备类型管理',
        component: () => import('@/views/assemblyConfig/index'),
        meta: { title: '设备类型管理', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/equipment',
    component: Layout,
    redirect: '/equipment',
    name: 'tribunalEquipmentBrand',
    children: [
      {
        path: 'assemblyConfig',
        name: '组件管理',
        component: () => import('@/views/tribunalEquipmentBrand/index'),
        meta: { title: '组件管理', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/tribunalEquipment',
    component: Layout,
    redirect: '/tribunalEquipment',
    name: 'tribunalEquipment',
    children: [
      {
        path: 'assemblyConfig',
        name: '法庭设备管理',
        component: () => import('@/views/tribunalEquipment/index'),
        meta: { title: '法庭设备管理', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/powerChannelInfo',
    component: Layout,
    redirect: '/powerChannelInfo',
    name: 'powerChannelInfo',
    children: [
      {
        path: 'powerChannelInfo',
        name: '时序通道管理',
        component: () => import('@/views/powerChannelInfo/index'),
        meta: { title: '时序通道管理', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/powerManage',
    component: Layout,
    redirect: '/powerManage',
    name: 'powerManage',
    children: [
      {
        path: 'powerManage',
        name: '开关统一管理',
        component: () => import('@/views/powerManage/index'),
        meta: { title: '开关统一管理', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/cameraConfig',
    name: 'Example',
    children: [
      {
        path: 'cameraConfig',
        name: '法庭摄像头配置',
        component: () => import('@/views/camera/index'),
        meta: { title: '法庭摄像头配置', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/tribunalComputer',
    component: Layout,
    redirect: '/computerConfig',
    name: 'ComputerConfig',
    children: [
      {
        path: 'computerConfig',
        name: '法庭电脑配置',
        component: () => import('@/views/computer/index'),
        meta: { title: '法庭电脑配置', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/powerPasswd',
    component: Layout,
    redirect: '/powerPasswd',
    name: 'powerPasswd',
    children: [
      {
        path: 'powerPasswd',
        name: '时序电源管理密码',
        component: () => import('@/views/admin/powerPasswd'),
        meta: { title: '时序电源管理密码', icon: 'el-icon-setting' }
      }
    ]
  },
  // {
  //   path: '/monitor',
  //   component: Layout2,
  //   redirect: '/index',
  //   name: 'Monitor',
  //   group: 2,
  //   children: [
  //     {
  //       path: 'index',
  //       name: '法庭设备监控',
  //       component: () => import('@/views/monitor/index'),
  //       meta: { title: '法庭设备监控', icon: 'el-icon-setting' }
  //     }
  //   ]
  // },
  {
    path: '/monitor',
    component: Layout,
    redirect: '/index',
    name: 'Monitor',
    group: 1,
    children: [
      {
        path: 'index',
        name: '法庭设备监控',
        component: () => import('@/views/monitor/index'),
        meta: { title: '法庭设备监控', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/statistic',
    component: Layout,
    redirect: '/index',
    name: 'Statistic',
    group: 1,
    children: [
      {
        path: 'index',
        name: '设备巡查总览',
        component: () => import('@/views/statistic/index'),
        meta: { title: '设备巡查总览', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/statistic',
    component: Layout,
    redirect: '/index',
    name: 'Statistic',
    group: 1,
    children: [
      {
        path: 'day',
        name: '设备日巡查报告',
        component: () => import('@/views/statistic/day'),
        meta: { title: '设备日巡查报告', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/statistic',
    component: Layout,
    redirect: '/index',
    name: 'Statistic',
    group: 1,
    children: [
      {
        path: 'week',
        name: '设备周巡查报告',
        component: () => import('@/views/statistic/week'),
        meta: { title: '设备周巡查报告', icon: 'el-icon-setting' }
      }
    ]
  },
  {
    path: '/statistic',
    component: Layout,
    redirect: '/index',
    name: 'Statistic',
    group: 1,
    children: [
      {
        path: 'month',
        name: '设备月巡查报告',
        component: () => import('@/views/statistic/month'),
        meta: { title: '设备月巡查报告', icon: 'el-icon-setting' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
